
#include "VConfigs.hpp"

VConfigs * VConfigs::Get()
{
	static VConfigs * vc = nullptr;
	if(!vc) vc = new VConfigs;
	return vc;
}
VConfigs::VConfigs()
{
#define PATH(key, file) m_pathes[key] = file

	PATH("font0", "font0.ttf");
	PATH("pan", "pan.png");
	PATH("num", "num.png");
	PATH("block%d", "t%d.png");
	PATH("bar", "bar.png");
	PATH("sound rotate", "sound/beo.wav");
	PATH("sound tick", "sound/tick0.wav");
	PATH("sound cleared", "sound/cleared.wav");
	PATH("sound button", "sound/button.wav");
	PATH("sound move", "sound/move.wav");
	PATH("sound failed", "sound/failed.wav");
	PATH("sound bing", "sound/bing0.wav");

}
std::string VConfigs::getPath(std::string const & key)
{
	auto iter = m_pathes.find(key);
	if(iter == m_pathes.end()) return "";
	return "res/" + iter->second;
}
std::string VConfigs::getPath(std::string const & key, int index) {
	auto iter = m_pathes.find(key);
	if(iter == m_pathes.end()) return "";
	char buf[1024] = "res/";
	sprintf(buf + 4, iter->second.c_str(), index);
	return buf;
}

void VConfigs::initViewSize(Size2 size)
{
	float const h = 2048.f;
	float const w = 1024.f;
	float w1 = h * size.w / size.h;
	m_view_size = { w1, h };
	m_edge_size = { (w1 - w)/2.f, 0 };
}
